/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package shaman;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import javax.swing.AbstractListModel;

/**
 *
 * @author Shaman
 */
public class ListModel<T> extends AbstractListModel implements List<T> {

    List<T> _localList = null;

    public ListModel() {
        _localList = new ArrayList<T>();
    }

    public int getSize() {
        return _localList.size();
    }

    public Object getElementAt(int index) {
        return _localList.get(index);
    }

    public int size() {
        return _localList.size();
    }

    public boolean isEmpty() {
        return _localList.isEmpty();
    }

    @SuppressWarnings("element-type-mismatch")
    public boolean contains(Object o) {
        return _localList.contains(o);
    }

    public Iterator<T> iterator() {
        return _localList.iterator();
    }

    public Object[] toArray() {
        return _localList.toArray();
    }

    public <T> T[] toArray(T[] a) {
       return _localList.toArray(a);
    }

    public boolean add(T e) {
        boolean result = _localList.add(e);
        this.fireIntervalAdded(this, _localList.size()-1, _localList.size());
        return result;
    }

    public boolean remove(Object o) {
        boolean result = _localList.remove(o);
        this.fireIntervalRemoved(this, _localList.size(), _localList.size()+1);
        return result;
    }

    public boolean containsAll(Collection<?> c) {
        return _localList.containsAll(c);
    }

    public boolean addAll(Collection<? extends T> c) {
        int LastEnd = _localList.size() - 1;
        boolean result = _localList.addAll(c);
        this.fireIntervalAdded(this, LastEnd, _localList.size()-1);
        return result;
    }

    public boolean addAll(int index, Collection<? extends T> c) {
        int LastEnd = _localList.size() - 1;
        boolean result = _localList.addAll(index, c);
        this.fireIntervalAdded(this, LastEnd, _localList.size()-1);
        return result;
    }

    public boolean removeAll(Collection<?> c) {
        int LastEnd = _localList.size() - 1;
        boolean result = _localList.removeAll(c);
        this.fireIntervalAdded(this, LastEnd, _localList.size()-1);
        return result;
    }

    public boolean retainAll(Collection<?> c) {
        return _localList.retainAll(c);
    }

    public void clear() {
        int LastEnd = _localList.size() - 1;
        _localList.clear();
        this.fireIntervalAdded(this, LastEnd, _localList.size()-1);
    }

    public T get(int index) {
        return _localList.get(index);
    }

    public T set(int index, T element) {
        T result = _localList.set(index, element);
        this.fireContentsChanged(this, index, index+1);
        return result;
    }

    public void add(int index, T element) {
        _localList.add(index, element);
        this.fireContentsChanged(this, index, index+1);
    }

    public T remove(int index) {
        return _localList.remove(index);
    }

    public int indexOf(Object o) {
        return _localList.indexOf(o);
    }

    public int lastIndexOf(Object o) {
        return _localList.lastIndexOf(o);
    }

    public ListIterator<T> listIterator() {
        return _localList.listIterator();
    }

    public ListIterator<T> listIterator(int index) {
        return _localList.listIterator(index);
    }

    public List<T> subList(int fromIndex, int toIndex) {
        return _localList.subList(fromIndex, toIndex);
    }

}
